using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using BigNumbers;

namespace TestBigNumbers
{
    /// <summary>
    /// Summary description for TestBigInt.
    /// </summary>
    public partial class TestBigInt : System.Windows.Forms.Form
    {
        public TestBigInt()
        {
            InitializeComponent();
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new TestBigInt());
        }

        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            try
            {
                BigInt i1 = new BigInt(txtInt1.Text);
                BigInt i2 = new BigInt(txtInt2.Text);
                txtRes.Text = (i1 + i2).ToString();
            }
            catch (Exception ex)
            { MessageBox.Show(ex.ToString()); }

        }


        private void btnSub_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = (i1 - i2).ToString();
        }


        private void btnLT_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = (i1 < i2).ToString();
        }

        private void btnLTE_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = (i1 <= i2).ToString();
        }

        private void btnGTE_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = (i1 >= i2).ToString();
        }

        private void btnGT_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = (i1 > i2).ToString();
        }

        private void btnEQ_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = (i1 == i2).ToString();
        }

        private void btnDiff_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = (i1 != i2).ToString();
        }

        private void btnAbs_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = Calculus.Abs(i1).ToString();
        }

        private void btnPrime_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = (Calculus.IsPrime(i1)).ToString();
        }

        private void button1_Click_1(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtInt1.Text = (++i1).ToString();
            txtRes.Text = i1.ToString();
        }

        private void btnDec_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtInt1.Text = (--i1).ToString();
            txtRes.Text = i1.ToString();
        }

        private void btnMult_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = (i1 * i2).ToString();
        }

        private void btnFact_Click(object sender, System.EventArgs e)
        {
            long t1 = DateTime.Now.Ticks;
            BigInt i1 = new BigInt(txtInt1.Text);
            int i2 = Convert.ToInt32(txtInt2.Text);
            BigInt bi = Calculus.Fact(i1);
            long t2 = DateTime.Now.Ticks;
            txtRes.Text = bi.ToString();

            txtRes2.Text = ((t2 - t1) / 10000).ToString();
        }

        private void btnDiv_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            BigInt i3 = null;
            txtRes.Text = Calculus.Division(i1, i2, ref i3).ToString();
            txtRes2.Text = i3.ToString();
        }

        private void btnOdd_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = Calculus.Odd(i1).ToString();
        }

        private void btnEven_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = Calculus.Even(i1).ToString();
        }

        private void btnPow_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            int i2 = Convert.ToInt32(txtInt2.Text);
            txtRes.Text = Calculus.Pow(i1, i2).ToString();
        }

        private void btnPow10_Click(object sender, System.EventArgs e)
        {
            int i1 = Convert.ToInt32(txtInt1.Text);
            txtRes.Text = Calculus.Pow10(i1).ToString();
        }

        private void btnSqrt_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = Calculus.Sqrt(i1);
            txtRes.Text = i2.ToString();
            txtRes2.Text = (i2 * i2).ToString();

        }

        private void btnCast_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = ((long)i1).ToString();
        }

        private void btnDivisors_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt[] tab = Calculus.Divisors(i1);
            StringBuilder s = new StringBuilder();
            foreach (BigInt i in tab)
            {
                s.Append(i.ToString());
                s.Append(",");
            }
            txtRes.Text = s.ToString();

        }

        private void btnFactors_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt[] tab = Calculus.PrimeFactors(i1);
            StringBuilder s = new StringBuilder();
            foreach (BigInt i in tab)
            {
                s.Append(i.ToString());
                s.Append(",");
            }
            txtRes.Text = s.ToString();

        }

        private void btnPPCM_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = Calculus.PPCM(i1, i2).ToString();
        }

        private void btnPGCD_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            BigInt i2 = new BigInt(txtInt2.Text);
            txtRes.Text = Calculus.PGCD(i1, i2).ToString();
        }

        private void btnDicho_Click(object sender, System.EventArgs e)
        {
            BigInt i1 = new BigInt(txtInt1.Text);
            txtRes.Text = Calculus.SolveUnaryFunction(new Calculus.UnaryFunction(test), i1, 0, i1 * i1, Calculus.SolveType.Dichotomy).ToString();
        }

        private BigInt test(BigInt x)
        {
            return x * x * x;
        }

        private void btnTestBigRat_Click(object sender, System.EventArgs e)
        {
            using (TestBigRat f = new TestBigRat())
            {
                f.ShowDialog();
            }
        }
    }
}

